-module(parsers_test).

-include_lib("eunit/include/eunit.hrl").

image_success_parse_test() ->
	run_parser("tests/describe_images_good.xml", image_response_parser, ok, 312).
	
image_error_parse_test() ->
	run_parser("tests/describe_images_error.xml", image_response_parser, error, 1).

keypair_success_parse_test() ->
	run_parser("tests/describe_keys_good.xml", keypairs_response_parser, ok, 5).

keypair_error_parse_test() ->
	run_parser("tests/describe_keys_error.xml", keypairs_response_parser, error, 1).

run_parser(FileName, ParserName, ResponseType, ExpectedSize) ->
	{ok, Body} = file:read_file(FileName),
	B1 = binary_to_list(Body),	
	{ParsedType, Result} = erlsom:sax(B1, {[], [], []}, {aws_util:determine_parser(ParserName, B1), callback}),
	?assertEqual(ParsedType, ResponseType),
	?assertEqual(ExpectedSize, length(Result)),
	parser_test_util:validate(Result).